home *** CD-ROM | disk | FTP | other *** search
/ Zoom 2 / Zoom - Release 2 (1996)(Active Software)[!].iso / programming / amiga / visualarts / source / serialconsole / serialconsole.c < prev   
Encoding:
C/C++ Source or Header  |  1995-04-02  |  8.2 KB  |  317 lines

  1. /* ******************************************************************** */
  2. /* C code generated by:                            */
  3. /* Visual Arts Version 2.1                        */
  4. /* Copyright 1994-95 Danny Y. Wong  All rights reserved            */
  5. /* Calgary, Alberta (CANADA)                                    */
  6. /* Partial of the code is copyright by Jaba Development            */
  7. /* ******************************************************************** */
  8.  
  9. #include <VisualArts.h>
  10. #include <clib/VisualArts_protos.h>
  11.  
  12.  
  13. #include "SerialConsole_func.c" 
  14.  
  15.  
  16. int GetPubScreen(void);
  17. void ClosePubScreen(void);
  18. int OpenSerConWindow(char windtitle[]);
  19. void CloseSerConWindow(void);
  20. int InitSerConConsole(void);
  21. extern int SerConConsoleHandler(void);
  22. int InitSerConSerial(void);
  23. extern int SerConSerialHandler(void);
  24. int SerConHandler(void);
  25. int SerConMainHandler(void);
  26. void DrawSerConObjs(void);
  27. int main(int argc, char *argv[]);
  28.  
  29. UBYTE                *PubScrName = "Workbench";
  30. struct DrawInfo            *ScrDrawInfo = NULL;
  31. APTR                 VisualInfo = NULL;
  32. struct Screen            *Scr = NULL;
  33. struct Window            *SerConWnd = NULL;
  34. struct Window            *SerConConWnd = NULL;
  35. struct MsgPort            *SerConConWritePort = NULL;
  36. struct MsgPort            *SerConConReadPort = NULL;
  37. struct IOStdReq            *SerConConWriteReq = NULL;
  38. struct IOStdReq            *SerConConReadReq = NULL;
  39. struct MsgPort            *SerConSerWritePort = NULL;
  40. struct MsgPort            *SerConSerReadPort = NULL;
  41. struct IOExtSer            *SerConSerWriteReq = NULL;
  42. struct IOExtSer            *SerConSerReadReq = NULL;
  43. struct IntuiMessage         SerConMsg;
  44. UWORD                 SerConLeft = 43;
  45. UWORD                 SerConTop = 16;
  46. UWORD                 SerConWidth = 525;
  47. UWORD                 SerConHeight = 79;
  48. char                 character;
  49. struct TextAttr topaz8 = { (STRPTR)"topaz.font", 8, 0x00, 0x01 };
  50. struct TextAttr topaz800 = { (STRPTR)"topaz.font", 8, 0x00, 0x00 };
  51.  
  52. struct IntuiText SerConIText[] = {
  53.   1, 0, JAM2, 9, 1, &topaz800, (UBYTE *)"Instructions:", &SerConIText[1],
  54.   1, 0, JAM2, 19, 13, &topaz800, (UBYTE *)"1. Activate the Console Window", &SerConIText[2],
  55.   1, 0, JAM2, 19, 23, &topaz800, (UBYTE *)"2. Type in the command 'at' and press return", &SerConIText[3],
  56.   1, 0, JAM2, 19, 33, &topaz800, (UBYTE *)"3. You should get a 'OK' as a reply", &SerConIText[4],
  57.   1, 0, JAM2, 19, 43, &topaz800, (UBYTE *)"4. Now enter a BBS number you want to call and press return", &SerConIText[5],
  58.   1, 0, JAM2, 19, 53, &topaz800, (UBYTE *)"5. An example 1-403-2745545 in Calgary, Canada", NULL,
  59. };
  60.  
  61.  
  62. int GetPubScreen(void)
  63. {
  64.   if (!(Scr = LockPubScreen(PubScrName)))
  65.     return(1L);
  66.  
  67.   if (!(VisualInfo = GetVisualInfo(Scr, TAG_DONE)))
  68.     return(2L);
  69.  
  70.   if (!(ScrDrawInfo = GetScreenDrawInfo(Scr)))
  71.     return(3L);
  72.   return(0L);
  73. }
  74.  
  75. void ClosePubScreen(void)
  76. {
  77.   if (VisualInfo)
  78.     FreeVisualInfo(VisualInfo);
  79.   if (Scr)
  80.     UnlockPubScreen(NULL,  Scr);
  81.   if (ScrDrawInfo)
  82.     FreeScreenDrawInfo(Scr,  ScrDrawInfo);
  83. }
  84.  
  85. int InitSerConConsole(void)
  86. {
  87.   SerConConWnd = OpenWindowTags( NULL,
  88.     WA_Left,        0,
  89.     WA_Top,            100,
  90.     WA_Width,        640,
  91.     WA_Height,        100,
  92.     WA_Title,        "Console Window",
  93.     WA_IDCMP,        NULL,
  94.     WA_Flags,        WFLG_DRAGBAR | WFLG_SIMPLE_REFRESH |
  95.                   WFLG_DEPTHGADGET | WFLG_SIZEGADGET | WFLG_SIZEBRIGHT,
  96.     WA_CustomScreen,    Scr,
  97.       WA_MaxWidth,        640,
  98.       WA_MaxHeight,        200,
  99.     TAG_DONE );
  100.  
  101.   if ( SerConConWnd == NULL )
  102.     return(6L);
  103.  
  104.   SerConConWritePort = CreatePort("SerCon.con.write", 0);
  105.   if ( !SerConConWritePort)
  106.     return(1L);
  107.   SerConConWriteReq = CreateStdIO(SerConConWritePort);
  108.   if ( !SerConConWriteReq)
  109.     return(2L);
  110.   SerConConReadPort = CreatePort("SerCon.con.read", 0);
  111.   if ( !SerConConReadPort)
  112.     return(3L);
  113.   SerConConReadReq =  CreateStdIO(SerConConReadPort);
  114.   if ( !SerConConReadReq)
  115.     return(4L);
  116.   if ((OpenConsole(SerConConWriteReq, SerConConReadReq, SerConConWnd)) != 0)
  117.     return(5L);
  118.  
  119.   return(0L);
  120. }
  121.  
  122.  
  123. int InitSerConSerial(void)
  124. {
  125.   SerConSerWritePort = CreatePort("SerCon.ser.write", 0);
  126.   if ( !SerConSerWritePort)
  127.     return(1L);
  128.   SerConSerWriteReq = (struct IOExtSer *)CreateExtIO(SerConSerWritePort, sizeof(struct IOExtSer));
  129.   if ( !SerConSerWriteReq)
  130.     return(2L);
  131.   SerConSerReadPort = CreatePort("SerCon.ser.read", 0);
  132.   if ( !SerConSerReadPort)
  133.     return(3L);
  134.   SerConSerReadReq =  (struct IOExtSer *)CreateExtIO(SerConSerReadPort, sizeof(struct IOExtSer));
  135.   if ( !SerConSerReadReq)
  136.     return(4L);
  137.   if ((OpenSerial(SerConSerReadReq, SerConSerWriteReq)) != 0)
  138.     return(5L);
  139.   if ((SetParams( SerConSerReadReq, 4096, 8, 8, 750000L,
  140.      19200,  SERF_XDISABLED | SERF_SHARED , 48484848, 48484848)) != 0)
  141.     return(6L);
  142.   return(0L);
  143. }
  144.  
  145.  
  146. int OpenSerConWindow(char windtitle[80])
  147. {
  148.   if (!(SerConWnd = OpenWindowTags(NULL,
  149.       WA_Left,    SerConLeft,
  150.       WA_Top,     SerConTop,
  151.       WA_Width,    SerConWidth,
  152.       WA_Height,    SerConHeight + kWindowOffSetY,
  153.       WA_NewLookMenus, TRUE,
  154.       WA_IDCMP,    IDCMP_CLOSEWINDOW | IDCMP_GADGETUP ,
  155.       WA_Flags,    WFLG_CLOSEGADGET  |  WFLG_SMART_REFRESH | 
  156.              WFLG_RMBTRAP |  WFLG_ACTIVATE | 
  157.              WFLG_DRAGBAR ,
  158.       WA_Gadgets,    NULL,
  159.       WA_Title,    windtitle,
  160.       WA_ScreenTitle,    "Visual Arts V2.2 Copyright 1994-95 Danny Y. Wong  All Rights Reserved.",
  161.       WA_PubScreen,    Scr,
  162.       WA_MinWidth,    160,
  163.       WA_MinHeight,    50,
  164.       WA_MaxWidth,    640,
  165.       WA_MaxHeight,    200,
  166.       TAG_DONE)))
  167.           return(3L);
  168.  
  169.   DrawSerConObjs();
  170.   GT_RefreshWindow(SerConWnd, NULL);
  171.   if (InitSerConConsole())
  172.     return(4L);
  173.   if (InitSerConSerial())
  174.     return(5L);
  175.   return(0L);
  176. }
  177.  
  178. void CloseSerConWindow(void)
  179. {
  180.   if (SerConConWnd)
  181.     CloseWindow(SerConConWnd);
  182.   if (SerConConWriteReq)
  183.     CloseDevice((struct IORequest *)SerConConWriteReq);
  184.   if (SerConConReadReq)
  185.     DeleteStdIO(SerConConReadReq);
  186.   if (SerConConReadPort)
  187.     DeletePort(SerConConReadPort);
  188.   if (SerConConWriteReq)
  189.     DeleteStdIO(SerConConWriteReq);
  190.   if (SerConConWriteReq)
  191.     DeletePort(SerConConWritePort);
  192.   AbortIO((struct IORequest *)SerConSerReadReq);
  193.   WaitIO((struct IORequest *)SerConSerReadReq);
  194.   if (SerConSerWriteReq)
  195.     CloseDevice((struct IORequest *)SerConSerWriteReq);
  196.   if (SerConSerReadReq)
  197.     DeleteExtIO( (struct IORequest *)SerConSerReadReq);
  198.   if (SerConSerReadPort)
  199.     DeletePort(SerConSerReadPort);
  200.   if (SerConSerWriteReq)
  201.     DeleteExtIO( (struct IORequest *)SerConSerWriteReq);
  202.   if (SerConSerWriteReq)
  203.     DeletePort(SerConSerWritePort);
  204.   if (SerConWnd)
  205.     CloseWindow(SerConWnd);
  206. }
  207.  
  208. int SerConHandler(void)
  209. {
  210.   struct IntuiMessage    *msg;
  211.   struct VAobject    VAObject;
  212.   int running    = 1;
  213.   int (*func)(struct VAobject VAObject);
  214.   ULONG class;
  215.   UWORD code;
  216.  
  217.   while (msg=GT_GetIMsg(SerConWnd->UserPort))
  218.   {
  219.     CopyMem((char *)msg, (char *)&SerConMsg, (long)sizeof(struct IntuiMessage));
  220.     class = msg->Class;
  221.     code  = msg->Code;
  222.  
  223.     GT_ReplyIMsg(msg);
  224.     switch(class)
  225.     {
  226.  
  227.       case IDCMP_CLOSEWINDOW:
  228.          return(0);
  229.          break;
  230.  
  231.       case IDCMP_GADGETUP:
  232.         func = (void *)((struct Gadget *)SerConMsg.IAddress)->UserData;
  233.         if (func != NULL)
  234.           running =  func(VAObject);
  235.         break;
  236.  
  237.     }
  238.   }
  239.   return(running);
  240. }
  241.  
  242. void DrawSerConObjs(void)
  243. {
  244.   PrintIText(SerConWnd->RPort, SerConIText, SerConWnd->BorderLeft, SerConWnd->BorderTop);
  245.  
  246. }
  247.  
  248. int SerConConsoleHandler(void)
  249. {
  250.   while( CheckIO((struct IORequest *)SerConConReadReq))
  251.   {
  252.     WaitIO( (struct IORequest *)SerConConReadReq);
  253.     SerPutChar(SerConSerWriteReq, character);    /* write to serial */
  254.     QueueRead(SerConConReadReq, &character);
  255.   }
  256.   return(1);
  257. }
  258.  
  259.  
  260. int SerConSerialHandler(void)
  261. {
  262.   while( CheckIO((struct IORequest *)SerConSerReadReq))
  263.   {
  264.     WaitIO( (struct IORequest *)SerConSerReadReq);
  265.     ConPutChar(SerConConWriteReq, character);    /* write to console */
  266.     QueueSerRead(SerConSerReadReq, &character);
  267.   }
  268.   return(1);
  269. }
  270.  
  271.  
  272. int SerConMainHandler(void)
  273. {
  274.   int running = 1;
  275.   ULONG windsig, signals;
  276.  
  277.   ULONG consolesig;
  278.   ULONG serialsig;
  279.   QueueRead(SerConConReadReq, &character);
  280.   consolesig = 1L << SerConConReadReq->io_Message.mn_ReplyPort->mp_SigBit;
  281.   QueueSerRead(SerConSerReadReq, &character);
  282.   serialsig = 1L << SerConSerReadReq->IOSer.io_Message.mn_ReplyPort->mp_SigBit;
  283.   windsig = 1L << SerConWnd->UserPort->mp_SigBit;
  284.  
  285.   while (running == 1)
  286.   {
  287.     signals = Wait( windsig | consolesig | serialsig );
  288.     if (signals & windsig)
  289.     {
  290.       running = SerConHandler();
  291.     }
  292.     else
  293.     if (signals & consolesig)
  294.       running = SerConConsoleHandler();
  295.     else
  296.     if (signals & serialsig)
  297.       running = SerConSerialHandler();
  298.   }
  299.   return(running);
  300. }
  301.  
  302. int main(int argc, char *argv[])
  303. {
  304.   int rc;
  305.  
  306.   if (!(GetPubScreen()))
  307.   {
  308.     if (!(OpenSerConWindow("Serial and Console Demo - Unmodified Codes")))
  309.     {
  310.       rc = SerConMainHandler();
  311.       CloseSerConWindow();
  312.     }
  313.     ClosePubScreen();
  314.   }
  315.   return(0L);
  316. }
  317.